package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.CountryMapper;
import org.rcloud.io.model.Country;
import org.rcloud.io.service.CountryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/4/2.
 */
@Service(value = "/CountryService")
public class CountryServiceImpl implements CountryService {
    @Autowired
    private CountryMapper countryMapper;

    @Override
    public ResultVo deleteByPrimaryKey(String id) {
        try {
            countryMapper.deleteByPrimaryKey(id);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo insert(Country record) {
        if (record.equals("")||record == null) {
            return ResultVo.setError("传入的数据为空!");
        } else {
            try {
                countryMapper.insert(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo insertSelective(Country record) {
        if (record.equals("")||record == null) {
            return ResultVo.setError("传入的数据为空!");
        } else {
            try {
                int i = countryMapper.insertSelective(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo selectByKey(Country id) {
        try {
            Country country = countryMapper.selectByKey(id);
            return ResultVo.setOK(country);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo updateByPrimaryKeySelective(Country record) {
        if (record.equals("")||record == null) {
            return ResultVo.setError("传入的数据为空!");
        } else {
            try {
                countryMapper.updateByPrimaryKeySelective(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo updateByPrimaryKey(Country record) {
        if (record.equals("")||record == null) {
            return ResultVo.setError("传入的数据为空!");
        } else {
            try {
                countryMapper.updateByPrimaryKey(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public PageVo<Country> selectAll() {
        try {
            List<Country> list = countryMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public PageVo<Country> selectByid(Country record) {
        try {
            List<Country> list = countryMapper.selectByid(record);
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }
}
